<?php

namespace common\models\c2\entity;

use Yii;

/**
 * This is the model class for table "{{%sales_order_item}}".
 *
 * @property string $id
 * @property string $sales_order_id
 * @property string $label
 * @property string $product_id
 * @property string $product_label
 * @property string $product_sku_id
 * @property string $sku_label
 * @property string $supplier_id
 * @property string $package_id
 * @property string $package_label
 * @property string $measure_id
 * @property integer $pieces
 * @property integer $quantity
 * @property string $price
 * @property integer $send_pieces
 * @property string $subtotal
 * @property string $memo
 * @property integer $status
 * @property integer $position
 * @property string $created_at
 * @property string $updated_at
 */
class SalesOrderItem extends \kzo\base\models\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%sales_order_item}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sales_order_id', 'product_id', 'package_id', 'measure_id', 'pieces', 'quantity', 'send_pieces', 'status', 'position'], 'integer'],
            [['price', 'subtotal'], 'number'],
            [['created_at', 'updated_at'], 'safe'],
            [['label', 'product_label', 'product_sku_id', 'sku_label', 'supplier_id', 'package_label', 'memo'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app.c2', 'ID'),
            'sales_order_id' => Yii::t('app.c2', 'Sales Order ID'),
            'label' => Yii::t('app.c2', 'Label'),
            'product_id' => Yii::t('app.c2', 'Product ID'),
            'product_label' => Yii::t('app.c2', 'Product Label'),
            'product_sku_id' => Yii::t('app.c2', 'Product Sku ID'),
            'sku_label' => Yii::t('app.c2', 'Sku Label'),
            'supplier_id' => Yii::t('app.c2', 'Supplier ID'),
            'package_id' => Yii::t('app.c2', 'Package ID'),
            'package_label' => Yii::t('app.c2', 'Package Label'),
            'measure_id' => Yii::t('app.c2', 'Measure ID'),
            'pieces' => Yii::t('app.c2', 'Pieces'),
            'quantity' => Yii::t('app.c2', 'Quantity'),
            'price' => Yii::t('app.c2', 'Price'),
            'send_pieces' => Yii::t('app.c2', 'Send Pieces'),
            'subtotal' => Yii::t('app.c2', 'Subtotal'),
            'memo' => Yii::t('app.c2', 'Memo'),
            'status' => Yii::t('app.c2', 'Status'),
            'position' => Yii::t('app.c2', 'Position'),
            'created_at' => Yii::t('app.c2', 'Created At'),
            'updated_at' => Yii::t('app.c2', 'Updated At'),
        ];
    }

    /**
     * @inheritdoc
     * @return \common\models\c2\query\SalesOrderItemQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \common\models\c2\query\SalesOrderItemQuery(get_called_class());
    }
    
    /**
    * setup default values
    **/
    public function loadDefaultValues($skipIfSet = true) {
        parent::loadDefaultValues($skipIfSet);
    }

    public function getOwner()
    {
        return $this->hasOne(SalesOrder::className(), ['id' => 'sales_order_id']);
    }

    public function getProduct()
    {
        return $this->hasOne(Product::className(), ['id' => 'product_id']);
    }

    public function getProductSku()
    {
        return $this->hasOne(ProductSku::className(), ['id' => 'product_sku_id']);
    }

    public function getPackage()
    {
        return $this->hasOne(ProductPackage::className(), ['id' => 'package_id']);
    }

}
